package com.hotel.api.service.impl;

import com.hotel.api.service.RepairService;
import com.hotel.api.entity.UserRepairOrder;
import com.hotel.api.mapper.UserRepairorderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @Author 涛涛
 * @Create 2019/8/29
 */

@Service
public class RepairServiceImpl implements RepairService {

    @Autowired
    private UserRepairorderMapper userRepairorderMapper;

    /**
     * 查看用户的所有保修订单信息集合
     *
     * @param uid 用户id
     * @return List<UserRepairOrder>
     */
    @Override
    public List<UserRepairOrder> selectRepairOrderByUid(Integer uid) {
        return userRepairorderMapper.selectRepairOrderByUid(uid);
    }

    /**
     * 根据报修单状态查看用户的所有保修订单信息集合
     *
     * @param uid   用户id
     * @param State
     * @return List<UserRepairOrder>
     */
    @Override
    public List<UserRepairOrder> selectRepairOrderByUidAndState(Integer uid, Byte State) {
        return userRepairorderMapper.selectRepairOrderByUidAndState(uid, State);
    }

    /**
     * 查看指定保修单信息
     *
     * @param id 保修单id
     * @return UserRepairOrder
     */
    @Override
    public UserRepairOrder selectRepairOrderById(Integer id) {
        return userRepairorderMapper.selectRepairOrderById(id);
    }

    /**
     * 新增保修单信息
     *
     * @param record 保修单信息
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insert(UserRepairOrder record) {
        return userRepairorderMapper.insert(record);
    }

    /**
     * 保修完成，用户要更改状态并进行评价
     *
     * @param userRepairOrder 部分信息
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateRepairOrderAssess(UserRepairOrder userRepairOrder) {
        return userRepairorderMapper.updateRepairOrderAssess(userRepairOrder);
    }

    /**
     * 用户取消保修单
     *
     * @param userRepairOrder 删除状态
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteRepairOrderById(UserRepairOrder userRepairOrder) {
        return userRepairorderMapper.deleteRepairOrderById(userRepairOrder);
    }

    /**
     * 查询所有保修单的信息集合
     *
     * @return List<UserRepairOrder>
     */
    @Override
    public List<UserRepairOrder> selectAll() {
        return userRepairorderMapper.selectAll();
    }

    @Override
    public List<UserRepairOrder> workerSelectAll(Integer state) {
        return userRepairorderMapper.workerSelectAll(state);
    }

    @Override

    public int update(UserRepairOrder userRepairOrder) {
        return userRepairorderMapper.update(userRepairOrder);
    }

}
